{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in new...\n",
      "in init...\n"
     ]
    }
   ],
   "source": [
    "class User:\n",
    "    def __new__(cls, *args, **kwargs):\n",
    "        print('in new...')\n",
    "        return super().__new__(cls)\n",
    "    \n",
    "    def __init__(self, name):\n",
    "        self.name = name\n",
    "        print('in init...')\n",
    "        \n",
    "## new 是用来控制对象的生成过程，在对象生成之前\n",
    "## init 是用来完善对象的\n",
    "## 如果new方法不返回对象，则不会调用init方法\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    user = User(name=\"bobby\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
